package gunPowderMod.block;

import gunPowderMod.GunPowderMod;
import gunPowderMod.entities.MiningDynamitePrimed;
import net.minecraft.src.Block;
import net.minecraft.src.BlockTNT;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.EntityTNTPrimed;
import net.minecraft.src.Item;
import net.minecraft.src.Material;
import net.minecraft.src.World;

public class MiningDynamite extends BlockTNT {
	private int blockIndexInTexture = 16;

	public MiningDynamite(int blockId) {
		super(blockId, 1);
		setBlockName("gpmMiningDynamite");
	}

	public int getBlockTextureFromSide(int par1) {
		return par1 == 0 ? this.blockIndexInTexture + 2
				: (par1 == 1 ? this.blockIndexInTexture + 1
						: this.blockIndexInTexture);
	}

	/**
	 * Called right before the block is destroyed by a player. Args: world, x,
	 * y, z, metaData
	 */
	@Override
	public void onBlockDestroyedByPlayer(World par1World, int par2, int par3,
			int par4, int par5) {
		if (!par1World.isRemote) {
			if ((par5 & 1) == 1) {
				MiningDynamitePrimed var6 = new MiningDynamitePrimed(par1World,
						(double) ((float) par2 + 0.5F),
						(double) ((float) par3 + 0.5F),
						(double) ((float) par4 + 0.5F));
				par1World.spawnEntityInWorld(var6);
				par1World.playSoundAtEntity(var6, "random.fuse", 1.0F, 1.0F);
			}
		}
	}

	@Override
	public void onBlockDestroyedByExplosion(World par1World, int par2,
			int par3, int par4) {
		if (!par1World.isRemote) {
			MiningDynamitePrimed var5 = new MiningDynamitePrimed(par1World,
					(double) ((float) par2 + 0.5F),
					(double) ((float) par3 + 0.5F),
					(double) ((float) par4 + 0.5F));
			var5.fuse = par1World.rand.nextInt(var5.fuse / 4) + var5.fuse / 8;
			par1World.spawnEntityInWorld(var5);
		}
	}

	@Override
	public String getTextureFile() {
		return GunPowderMod.blockTexturePath;
	}
}
